<template>
	<view>
		<view class="content">
			<z-paging ref="paging" :refresher-only="true" :fixed="false" @query="GetWorkInfo">
				<template #top>
					<u-navbar :fixed="false" title="工单详情" :autoBack="true" :safeAreaInsetTop="true"
						leftIconColor="#fff">
					</u-navbar>
				</template>
				<view class="TopCardBox">

					<!-- <uni-icons v-if="PageInfoData.Approve" color="#a3e8c3" custom-prefix="iconfont" type="icon-Audit"
						size="100rpx" class="ApprovalIcon"></uni-icons> -->
					<uni-icons v-if="PageInfoData.Approve" fontFamily="CustomFontPlatform" class="ApprovalIcon"
						color="#a3e8c3" size="100rpx">{{$utils.toUniCode('&#xeda6;')}}</uni-icons>

					<view class="TypeText"
						:style="{color:BackColor(PageInfoData).ModelColor,background:BackColor(PageInfoData).MenuBac}">
						<text>{{PageInfoData.FStateName}}</text>
					</view>

					<view class="BillNO">
						<text>{{PageInfoData.BillNO}}</text>
					</view>

					<view style="margin: 10px 0 0;">
						<m-field valueFontSize="16" labelFontSize="16" paddings="4px 0" :borderBottom="false"
							label="计划时间:" value="2024-03-04 ~ 2024-03-04"></m-field>
						<m-field valueFontSize="16" labelFontSize="16" paddings="4px 0" :borderBottom="false"
							label="产品信息:" overflow="wrap">
							<template v-slot:custom-value>
								<view class="x-f">
									<text>{{PageInfoData.ProductName}}</text>
								</view>
							</template>
						</m-field>
						<m-field valueFontSize="16" labelFontSize="16" paddings="4px 0" :borderBottom="false"
							label="工单进度:">
							<template v-slot:custom-value>
								<view class="x-f">
									<text>{{PageInfoData.WCQty}}</text>
									<text>/</text>
									<text>{{PageInfoData.FPlanQty}}</text>
									<text>{{PageInfoData.UnitName}}</text>
								</view>
							</template>
						</m-field>

						<view v-if="ArrowType">
							<m-field valueFontSize="16" labelFontSize="16" paddings="4px 0" :borderBottom="false"
								label="生产车间:" :value="PageInfoData.FWorkshopName"></m-field>

							<m-field valueFontSize="16" labelFontSize="16" paddings="4px 0" :borderBottom="false"
								label="是否线性:" :value="BackMap('IsLinear',PageInfoData.IsLinear)"></m-field>

							<m-field valueFontSize="16" labelFontSize="16" paddings="4px 0" :borderBottom="false"
								label="备注:" value="-"></m-field>

							<m-field valueFontSize="16" labelFontSize="16" paddings="4px 0" :borderBottom="false"
								label="附件:">
								<template v-slot:custom-value>
									<view v-if="PageInfoData.Filepath">
										<!-- 判断类型 -->
										<view v-if="PageInfoData.PathType == 'Pic'">
											<image style="width: 200rpx;height: 100rpx;" mode="aspectFit"
												:src="PageInfoData.Filepath" @click="preview(PageInfoData.Filepath)">
											</image>
										</view>

										<view v-else-if="PageInfoData.PathType == 'File'">
											<button class="button" size="mini"
												style="background-color: #51d0d0;color: #fff;"
												@click="OpenFileBtn">查看附件</button>

											<!-- <view @click="OpenFileBtn">{{PageInfoData.Filepath}}</view> -->
										</view>
									</view>

									<view v-else>-</view>
								</template>
							</m-field>
						</view>

						<!-- 箭头 -->
						<view class="ArrowBox">
							<view v-if="!ArrowType" class="x-f" @click="ClickArrow('open')"
								style="justify-content: center;padding: 4px 0;font-weight: 600;">
								<u-icon name="arrow-down" color="#b5b5b5" size="18"></u-icon>
							</view>

							<view v-else class="x-f" @click="ClickArrow('close')"
								style="justify-content: center;padding: 4px 0;font-weight: 600;">
								<u-icon name="arrow-up" color="#b5b5b5" size="18"></u-icon>
							</view>

						</view>
					</view>
				</view>

				<!-- 吸顶Tab栏 -->
				<u-sticky style="background-color: #fff;top: 0 !important;box-shadow: 0 8px 11px -19px;">
					<u-tabs :list="TabList" :is-scroll="false" :current="current" @change="clickHandler"
						activeStyle="color: #51d0d0;" lineWidth="50" lineColor="#51d0d0" :scrollable="false">
					</u-tabs>
				</u-sticky>

				<view class="MainBox" :style="{backgroundColor: current == 2 ? '#fff' : ''}">

					<!-- <view class="FilterBox" v-if="current == 0">
					<view class="Filter_right">
						<uni-icons color="#505050" custom-prefix="iconfont" type="icon-shaixuan" size="16"></uni-icons>
						<text style="margin-left: 6px;">筛选</text>
					</view>
				</view> -->

					<!-- 生产进度 -->
					<view class="Main_CardListBox" v-if="current == 0">
						<view class="CardBox" v-for="(item,index) in ProgressList" :key="index">
							<view class="Main_Card_Top">
								<view class="Main_Card_LeftBox x-f">
									<!-- 序号 + 名称 -->
									<view class="OrdinalBox">
										<text>{{index + 1}}</text>
									</view>

									<view class="Title_Text x-f">
										<text>{{item.ProcedureName}}</text>

										<u-tag v-if="item.Outsource" text="外协" style="margin-left: 10rpx;" size="mini"
											type="warning"></u-tag>

										<!-- <u-tag v-else text="自制" style="margin-left: 10rpx;" size="mini"></u-tag> -->
									</view>
								</view>

								<view class="Main_Card_RightBox">
									<view class="TypeText"
										:style="{color:BackColor(item).ModelColor,background:BackColor(item).MenuBac}">
										<text>{{item.FStateName}}</text>
									</view>
								</view>
							</view>

							<!-- 进度 -->
							<view class="CommonBox">
								<view class="TextBox">
									<text>计划数</text>
									<text class="BottomText">{{item.FPlanQty}}</text>
								</view>

								<view class="TextBox">
									<text>良品数</text>
									<text class="BottomText">{{item.FDailyQtt}}</text>
								</view>

								<view class="TextBox">
									<text>不良数</text>
									<text class="BottomText" style="color: #e13a2b;">{{item.FNgQty}}</text>
								</view>

								<view class="Progress" style="flex: 1;">
									<m-progress-circle :progress="Number(item.ProgressNum)" :canvasId="String(index)"
										:radius="30" :lineWidth="4" :innerTextSize="16"
										:innerTextColor="BackColor(item).ModelColor"
										:progressColor="BackColor(item).ModelColor" :BottomTextSize="12">
										<!-- <template #content>
											<view
												style="background-color: #f9f9f9;min-width: 94%;text-align: center;font-size: 12rpx;"
												:style="{color:BackColor(item).ModelColor }">
												{{item.ProgressNum}}%
											</view>
										</template> -->
									</m-progress-circle>
								</view>
							</view>

							<!-- 目标良品数 -->
							<!-- <view class="CommonBox">
								<view class="LeftIcon">
									<text>良</text>
								</view>

								<view class="CenterBox">
									<u--input v-model="item.AwaitWorkQty" placeholder="请输入" border="none" type="number"
										:readonly="item.FState == 1 || item.FState == -1"
										style="background-color: #fff;height: 40px;line-height: 40px;padding-left: 10px;"></u--input>
								</view>
							</view> -->

							<!-- 报工 -->
							<view class="ShowSigningWork">
								<button v-if="item.sopFile" class="button"
									style="background-color: #51d0d0;color: #fff;"
									@click="OpenWorkBook(item)">作业指导书</button>

								<!-- <button class="button"
									:disabled="item.FState == 1 || item.FState == -1 || item.ReportQty == 0 || !PageInfoData.Approve"
									:style="{opacity: item.FState == 1 || item.FState == -1 || item.ReportQty == 0 || !PageInfoData.Approve ? 0.4 : 1}"
									style="border: 1px solid #01b87d;color: #01b87d;"
									@click="SubWorkBtn(item,index)">报工</button> -->

							</view>

						</view>
					</view>

					<!-- 用料明细 -->
					<view class="Main_CardListBox" v-else-if="current == 1">
						<view class="CardBox" v-for="(item,index) in MaterialList" :key="index">
							<view class="Xuhao_YL">
								<text>{{index + 1}}</text>
							</view>


							<m-field labelWidth="100%" labelFontSize="18" labelColor="#333" paddings="15rpx 0"
								:borderBottom="true" :label="item.ProductCode"></m-field>

							<view style="margin-top: 8px;">
								<m-field valueFontSize="12" labelFontSize="12" paddings="4px" :borderBottom="false"
									label="产品名称:" :value="item.ProductName"></m-field>

								<m-field valueFontSize="12" labelFontSize="12" paddings="4px" :borderBottom="false"
									label="父件基数:" :value="item.ParentNum"></m-field>

								<m-field valueFontSize="12" labelFontSize="12" paddings="4px" :borderBottom="false"
									label="子件用量:" :value="item.SunNume"></m-field>

								<m-field valueFontSize="12" labelFontSize="12" paddings="4px" :borderBottom="false"
									label="损耗率:" :value="item.LossRatio"></m-field>

								<m-field valueFontSize="12" labelFontSize="12" paddings="4px" :borderBottom="false"
									label="需领数量:" :value="item.NeedQty"></m-field>

								<m-field valueFontSize="12" labelFontSize="12" paddings="4px" :borderBottom="false"
									label="最低需领数量:" :value="item.LimitQty"></m-field>

								<m-field valueFontSize="12" labelFontSize="12" paddings="4px" :borderBottom="false"
									label="单位:" :value="item.UnitName"></m-field>
							</view>
						</view>
					</view>

					<!-- 生产履历 -->
					<view class="Main_CardListBox" style="background-color: #fff;" v-if="current == 2">
						<view v-for="(item,index) in HistoryList" :key="index">
							<view class="DateBox x-f">
								<view class="x-f"
									style="background-color: #c8eed5;width: 24px;height: 24px;border-radius: 9999px;justify-content: center;zoom: .6;">
									<view
										style="background-color: #40d37d;width: 14px;height: 14px;border-radius: 9999px;">
									</view>
								</view>
								<text style="font-size: 15px;color: #999;margin-left: 4px;">{{item.date}}</text>
							</view>


							<view class="CardMainBox" style="padding: 10px 10px;">
								<view class="CardBox" v-for="(row,ind) in item.ArrData" :key="ind"
									style="padding: 10px;background-color: #f9f9f9;min-height: 100px;border-radius: 8px;color: #999;margin-bottom: 10px;">
									<view class="TopBox x-f" style="justify-content: space-between;">
										<view class="TopLeft x-f" style="flex: 1;">
											<u-tag :text="row.FType" plain></u-tag>
											<text
												style="font-weight: 600;color: #333;font-size: 16px;margin-left: 8px;">{{row.EmplName}}</text>

											<text
												style="font-weight: 600;color: #333;font-size: 16px;margin-left: 8px;">{{row.ProcedureName}}</text>
										</view>

										<view class="TopRight">
											{{row.Time}}
										</view>
									</view>

									<view style="margin-top: 8px;">
										<view class="MainRowBox x-f" style="padding: 4px 0;">
											<view>
												良品数：{{row.FPlanQty}}
											</view>

											<view style="margin-left: 30px;">
												不良数：{{row.FNgQty}}
											</view>
										</view>

										<!-- <view style="padding: 4px 0;">
											时长：0小时0分钟
										</view> -->
									</view>


								</view>

							</view>

						</view>


						<!-- 空状态 -->
						<u-empty v-if="!HistoryList.length" mode="data" text="暂无明细"
							icon="/static/image/Img/DataEmpty.png" width="50vw" height="50vw">
						</u-empty>

					</view>

				</view>


				<template #bottom>

					<view class="BottomBox safe_buttom" :style="$utils.disposeSafeBottomFun()">
						<button v-if="FCJType == 1 && ApproveBack('发放派工')" @click="OpenDispatchBtn"
							class="content_bottom_primary_Btn CommonBtnSize"
							style="min-width: 100px;margin-right: 10px !important;">发放派工</button>
						<button @click="EditOrderBtn" class="content_bottom_primary_plainBtn CommonBtnSize"
							style="min-width: 100px;">查看工单</button>
					</view>
				</template>
			</z-paging>




		</view>

		<q-previewImage ref="previewImage" :urls="[PageInfoData.Filepath]" @onLongpress="onLongpress"></q-previewImage>

		<!-- 报工弹层 -->
		<u-popup class="Popup_Main" :show="InitTicketPopup" mode="bottom" :round="12" @close="closeInitTicketPopup">
			<view class="Popup_Main_Content">
				<u-navbar :fixed="false" :autoBack="false" leftIcon=" " :safeAreaInsetTop="false" leftIconColor="#fff"
					style="width: 100%;">
					<view class="u-nav-slot x-f navbar_LeftBox" slot="left">
						<view class="Xuhao">
							{{PopupIndex}}
						</view>
						<view>
							{{PopupTopNums.ProcedureName}}
						</view>
					</view>
					<view class="u-nav-slot" slot="right">
						<uni-icons color="#fff" type="close" size="30" @click="closeInitTicketPopup"></uni-icons>
					</view>
				</u-navbar>

				<view class="Popup_Main_Content_MainBox">
					<u-grid :border="true" col="3">
						<u-grid-item>
							<view class="PopupGirdBox">
								计划数
							</view>
							<text class="grid-text">{{PopupTopNums.FPlanQty}}</text>
						</u-grid-item>

						<u-grid-item>
							<view class="PopupGirdBox">
								良品数
							</view>
							<text class="grid-text">{{PopupTopNums.FDailyQtt}}</text>
						</u-grid-item>

						<u-grid-item>
							<view class="PopupGirdBox">
								不良品数
							</view>
							<text class="grid-text">{{PopupTopNums.FNgQty}}</text>
						</u-grid-item>
					</u-grid>


					<u--form class="Popup_Form" labelPosition="left" :model="formData" :rules="rules" ref="uForm"
						:labelStyle="{'font-size':'24rpx'}">

						<u-form-item labelWidth="180rpx" v-if="FCJType == 1" class="Form_Item_top" label="派工单"
							borderBottom prop="JobOrderBillNO" leftIcon="share" :required="FCJType == 1"
							style="flex: 1;" @click="openBaseScreen('派工单','radio')"
							:leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="formData.JobOrderBillNO" readonly placeholder="请选择"
								border="none"></u--input>

							<view slot="right" class="x-f">
								<u-icon name="arrow-right" color="#999"></u-icon>
							</view>
						</u-form-item>

						<u-form-item labelWidth="180rpx" class="Form_Item_top" label="作业员" borderBottom prop="EmplName"
							leftIcon="share" required style="flex: 1;" @click="openBaseScreen('作业员','radio')"
							:leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="formData.EmplName" readonly placeholder="请选择" border="none"></u--input>

							<view slot="right" class="x-f">
								<u-icon name="arrow-right" color="#999"></u-icon>
							</view>
						</u-form-item>

						<u-form-item labelWidth="180rpx" label="计时计件" borderBottom prop="PieceTimeName" leftIcon="share"
							required style="flex: 1;" @click="openBaseScreen('计时计件','radio')"
							:leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="formData.PieceTimeName" readonly placeholder="请选择"
								border="none"></u--input>

							<view slot="right" class="x-f">
								<u-icon name="arrow-right" color="#999"></u-icon>
							</view>
						</u-form-item>

						<u-form-item labelWidth="180rpx" label="班次" prop="ShiftName" leftIcon="share" required
							@click="openBaseScreen('班次','radio')" style="flex: 1;"
							:leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="formData.ShiftName" readonly placeholder="请选择" border="none"></u--input>

							<view slot="right" class="x-f">
								<u-icon name="arrow-right" color="#999"></u-icon>
							</view>
						</u-form-item>


						<u-form-item labelWidth="180rpx" class="Form_Item_top" label="报工数" borderBottom prop="FPlanQty"
							disabled leftIcon="share" required style="flex: 1;" :leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="formData.FPlanQty" readonly border="none"></u--input>
						</u-form-item>

						<u-form-item labelWidth="180rpx" label="良品数" borderBottom prop="AwaitWorkQty" leftIcon="share"
							required style="flex: 1;" :leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="formData.AwaitWorkQty" placeholder="请输入" type="number"
								border="none"></u--input>
						</u-form-item>

						<view class="x-f">
							<u-form-item labelWidth="180rpx" label="工废数" leftIcon="share" style="flex: 1;"
								:leftIconStyle="{'font-size':'20px'}">
								<u--input v-model="formData.IndustrialWaste" placeholder="请输入" @input="InputNums"
									type="number" border="none"></u--input>
							</u-form-item>

							<u-form-item labelWidth="180rpx" class="Init_Item_PadLeft" label="料废数" leftIcon="share"
								style="flex: 1;" :leftIconStyle="{'font-size':'20px'}">
								<u--input v-model="formData.MaterialWaste" placeholder="请输入" @input="InputNums"
									type="number" border="none"></u--input>
							</u-form-item>
						</view>

						<view style="padding: 0 6px 0 16px;">
							<u-line></u-line>
						</view>

						<u-form-item labelWidth="180rpx" label="不良品数" prop="FNgQty" leftIcon="share" disabled
							style="flex: 1;" :leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="formData.FNgQty" readonly border="none"></u--input>
						</u-form-item>

						<u-form-item labelWidth="180rpx" class="Form_Item_top" label="报工时长" leftIcon="share"
							:required="formData.PieceTime != 0">
							<view class="x-f" style="width: 100%;">
								<view class="x-f" style="flex: 1;padding: 0 10px;">
									<u--input style="flex: 1;" type="number" v-model="formData.Hour" inputAlign="center"
										@input="ChangeDate" border="none" @blur="BlurDateIpt('hour')"></u--input>
									<text>小时</text>

									<u--input style="flex: 1;" type="number" v-model="formData.Minute"
										inputAlign="center" @input="ChangeDate" border="none"
										@blur="BlurDateIpt('minute')"></u--input>
									<text>分钟</text>
								</view>

								<view class="x-f" @click="OpenChoiceDate"
									style="height: 100%;min-width: 30px;justify-content: center;">
									<u-icon name="arrow-right" color="#999" size="20"></u-icon>
								</view>

							</view>
						</u-form-item>


						<u-form-item labelWidth="180rpx" label="模具编号" leftIcon="coupon"
							@click="openBaseScreen('模具编号','radio')" :leftIconStyle="{'font-size':'20px'}"
							style="margin-top: 10px;">
							<u--input v-model="formData.MoludCode" readonly placeholder="请选择" border="none"></u--input>

							<view slot="right" class="x-f">
								<u-icon name="arrow-right" color="#999"></u-icon>
							</view>
						</u-form-item>


						<u-form-item labelWidth="180rpx" label="设备/产线" leftIcon="share" style="flex: 1;"
							@click="openBaseScreen('设备','radio')" :leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="formData.EquipmentCode" readonly placeholder="请选择"
								border="none"></u--input>

							<view slot="right" class="x-f">
								<u-icon name="arrow-right" color="#999"></u-icon>
							</view>
						</u-form-item>

						<u-form-item labelWidth="180rpx" label="备注" leftIcon="attach"
							:leftIconStyle="{'font-size':'20px'}" class="TopOption" style="margin-top: 10px;">
							<view class="" style="padding: 10px 20px 0;width: 100%;">
								<u--textarea v-model="formData.Remark" placeholder="请输入内容" count
									maxlength="150"></u--textarea>
							</view>
						</u-form-item>

					</u--form>



				</view>

				<view class="Popup_Main_Content_BottomBox">
					<button class="content_bottom_primary_Btn moreBtn" @click="Popup_Submit_Btn"
						style="font-size: 24rpx;">提交</button>
				</view>

			</view>



			<!-- 报工时长时间选择器 -->
			<u-datetime-picker class="DateTimerPick" ref="datetimePickerBG" title="选择报工时长" :show="showTimePickerBG"
				v-model="DatetimeDataBG" mode="time" :closeOnClickOverlay="true" @close="ClosePickerBG"
				@cancel="ClosePickerBG" @confirm="ConfirmTimeBG" :formatter="formatter"></u-datetime-picker>
		</u-popup>


	</view>
</template>

<script>
	const open = uni.requireNativePlugin("Html5App-openFile");

	function throttle(func, delay) {
		let lastFunc;
		let lastRan;
		return function(...args) {
			const now = Date.now();
			if (!lastRan || (now - lastRan >= delay)) {
				lastFunc = func;
				lastRan = now;
				lastFunc.apply(this, args);
			}
		};
	}
	/* 新建工单 */
	export default {
		data() {
			return {
				ArrowType: false, // 展开 / 收缩
				current: 0,
				TabList: [{
						name: '生产进度'
					},
					{
						name: '用料明细'
					},
					{
						name: '生产履历'
					},
				],

				PageInfoData: {
					WCQty: '',
					FPlanQty: '',
					UnitName: '',
					FWorkshopName: '',
					IsLinear: '',
				}, // 工单详情数据
				ProgressList: [], // 生产进度列表数据

				MaterialList: [], // 用料明细列表数据

				HistoryList: [], // 生产履历列表数据

				InitTicketPopup: false, // 发起报工弹层
				FCJType: 2, // 查询公司报工类型 1、派工 2、工单
				PopupTopNums: {},
				PopupIndex: 1,

				WoOrderID: null,
				formData: {
					WoOrderID: null,

					JobOrderBillNO: null, // 派工单编号
					JobOrderID: null, // 派工单ID
					JobPROCID: null, // 派工单工序ID

					FWorkshopName: '', // 车间
					FWorkshopID: null, // 车间ID

					ProcedureName: '', // 工序
					ProcedureID: null, // 工序ID

					WoPROCID: null, // 工单工序

					PieceTimeName: '计件', // 计时计件
					PieceTime: '0', // 计时计件

					EmplName: null, // 作业员
					EmplID: null,

					FPlanQty: null, // 派工数
					ReportQty: null, // 可报工数
					WCQty: null, // 完成数
					FDailyQtt: null, // 
					AwaitWorkQty: null, // 外部良品数
					FNgQty: null, // 
					IndustrialWaste: null, // 工废数
					MaterialWaste: null, // 料废数

					EquipmentName: null, // 

					ShiftName: '白班', // 班次
					ShiftID: 1,

					MoludName: null, // 模具
					MoludCode: null, // 模具
					MoludID: null,
					MoludTypeID: null,

					EquipmentCode: null, // 设备/产线
					EquipmentID: null,

					Hour: 0, // 小时
					Minute: 0, // 分钟
					StartTime: null, // 开始时间
					EndTime: null, // 结束时间

					Remark: '',
				},
				rules: {
					'JobOrderBillNO': {
						type: 'string',
						required: true,
						message: '请选择派工单',
						trigger: ['change']
					},
					'FWorkshopName': { // 生产车间
						type: 'string',
						required: true,
						message: '生产车间不能为空',
						trigger: ['change']
					},
					'PieceTimeName': { // 计时计件
						type: 'string',
						required: true,
						message: '计时计件不能为空',
						trigger: ['change']
					},
					'EmplName': { // 作业员
						type: 'string',
						required: true,
						message: '作业员不能为空',
						trigger: ['change']
					},
					'AwaitWorkQty': { // 合格数
						type: 'number',
						required: true,
						message: '合格数不能为空',
						trigger: ['change']
					},
					'ShiftName': { // 班次
						type: 'string',
						required: true,
						message: '班次不能为空',
						trigger: ['change']
					},
				},

				PieceTimeNameData: [{
						PieceTimeName: '计件',
						PieceTime: 0
					},
					{
						PieceTimeName: '计时',
						PieceTime: 1
					}
				],


				showTimePickerBG: false, // 时间选择器弹层
				DatetimeDataBG: null, // 时间选择器时间

				DatetimeData: Number(new Date()), // 时间选择器时间
				showTimePicker: false, // 时间选择器弹层显示
				TimeType: '', // 区分时间 start - 开始 ， end - 结束
				PickerTitle: '', // 时间弹层标题
				BtnShow: false, // 按钮样式初始化有问题，等加载完再显示

				request1: null,
				request2: null,
				Timer_WorkBook: null, // 打开作业指导书的防抖定时器

				BtnApprove: [], // 权限数组
			}
		},
		onReady() {},
		onShow() {},
		onHide() {

			this.$utils.hideLoading();
		},
		onLoad(option) {
			var that = this;
			// console.log(option)
			// that.formData.WoOrderID = option.WoOrderID;
			that.WoOrderID = option.WoOrderID;


			let foundNode = null;
			// 获取页面按钮权限
			for (const module of this.$store.state.ModuleInfo_All) {
				if (module.TreeTypeName === '生产管理') {
					for (const node of module.Node) {
						if (node.APFunName === '新建工单') {
							foundNode = JSON.parse(JSON.stringify(node));
							break; // 找到后立即退出内层循环  
						}
					}
					if (foundNode) {
						break;
					}
				}
			};
			this.BtnApprove = foundNode['IconApprove'];

			const filteredObjects = foundNode['IconApprove'].filter(obj => {
				// 使用字符串的startsWith方法检查MenuName属性是否以"Info_"开头  
				return obj.MenuName && obj.MenuName.startsWith('Info_');
			});

			// console.log(filteredObjects)

			// 查询公司报工类型
			that.FCJType = this.$store.getters.GetFCJType;


			setTimeout(() => {
				that.GetWorkInfo();
				that.getTicketsHistory();
			}, 300)

		},
		mounted() {
			var that = this;

			uni.$on('TicketsInfo_Choice', function(ret) {
				// console.log(JSON.stringify(ret.data))
				if (ret.type == '生产车间') {
					that.formData.FWorkshopName = ret.data.FWorkshopName;
					that.formData.FWorkshopID = ret.data.FWorkshopID;
				} else if (ret.type == '模具编号') {
					that.formData = Object.assign(that.formData, ret.data);
				} else if (ret.type == '设备') {
					that.formData = Object.assign(that.formData, ret.data);
				} else if (ret.type == '班次') {
					that.formData = Object.assign(that.formData, ret.data);
				} else if (ret.type == '作业员') {
					that.formData = Object.assign(that.formData, ret.data);
				} else if (ret.type == '计时计件') {
					that.formData = Object.assign(that.formData, ret.data);
				} else if (ret.type == '派工单') {

					that.formData['JobOrderBillNO'] = ret.data.BillNO;
					that.formData['JobOrderID'] = ret.data.JobOrderID;
					that.formData['JobPROCID'] = ret.data.JobPROCID;
					Vue.set(that.formData, 'JobOrderBillNO', ret.data.BillNO);
					Vue.set(that.formData, 'JobOrderID', ret.data.JobOrderID);
					Vue.set(that.formData, 'JobPROCID', ret.data.JobPROCID);
					// console.log(JSON.stringify(that.formData))
				};

			});


			// 监听详情确认后，刷新页面
			uni.$on('ChangeTicketInfo', function(ret) {
				// console.log(JSON.stringify(ret))
				that.GetWorkInfo();

				setTimeout(() => {
					that.getTicketsHistory();
				}, 300)
			})

		},
		beforeDestroy() {
			if (uni.getStorageSync('NeedRemove')) {

				uni.removeSavedFile({
					filePath: uni.getStorageSync('NeedRemove'),
					complete: function(res) {
						// console.log(res);
						uni.removeStorageSync('NeedRemove')
					}
				});
			}

			if (uni.getStorageSync('FormNeedRemove')) {

				uni.removeSavedFile({
					filePath: uni.getStorageSync('FormNeedRemove'),
					complete: function(res) {
						// console.log(res);
						uni.removeStorageSync('FormNeedRemove')
					}
				});
			}
		},
		onUnload() { // 监听页面卸载,
			// 关闭监听器
			uni.$off('ChangeTicketInfo');
			uni.$off('TicketsInfo_Choice');

		},
		methods: {
			ApproveBack(str) {
				let that = this;
				let Type = that.BtnApprove.some(item => {
					return item.MenuName == str
				})

				return Type;
			},
			OpenDispatchBtn() { // 发放派工
				// console.log(this.PageInfoData)

				// console.log(this.ProgressList)

				let data = {
					form: this.PageInfoData,
					ProgressList: this.ProgressList,
				};

				let obj = {
					Name1: 'CreateTicket_Routing',
					data: data
				}

				this.$store.commit('TicketModule/ChangeAndSetStateData', obj);

				uni.navigateTo({
					url: './DispatchList/CreateDispatch'
				})

			},
			InputNums(str) { //
				let IndustrialWaste = +this.formData.IndustrialWaste || 0;
				let MaterialWaste = +this.formData.MaterialWaste || 0;
				this.formData.FNgQty = +IndustrialWaste + +MaterialWaste; // 合计报废数量
			},
			dateFormat(val, Type = 'MM-dd  hh:mm') { // 格式化时间
				var that = this;
				if (!that.$utils.isEmpty(val)) {
					return that.Request.dateFormat(new Date(val), Type);
				} else {
					return that.Request.dateFormat(new Date(), Type);
				}
			},
			ChangeDate() { // 报工时长输入框 input 事件
				var that = this;

				let Hour = +this.formData.Hour;
				// console.log(JSON.stringify(this.formData.Minute))
				let Minute = +(String(this.formData.Minute).replace(/\D/g, ''));

				if (Minute >= 60) {
					Hour += Math.floor(Minute / 60);
					that.$set(that.formData, 'Hour', String(Hour));

					that.$set(that.formData, 'Minute', String(1));
					setTimeout(() => {

						that.$set(that.formData, 'Minute', String(Minute % 60));
					}, 50)
				} else {
					that.$set(that.formData, 'Minute', String(Minute));
				}

				setTimeout(() => {

					let GetDate = (+that.formData.Hour * 60 * 1000 * 60) + (+that.formData.Minute * 60 * 1000);

					let NewData = that.Request.dateFormat(Number(new Date(that.formData.EndTime)) - GetDate,
						'MM-dd  hh:mm');

					that.$set(that.formData, 'StartTime', NewData);
				}, 500)
			},
			BlurDateIpt(str) { // 报工时长输入框失焦事件
				let that = this;
				switch (str) {
					case 'hour':
						that.formData.Hour = !that.$utils.isEmpty(that.formData.Hour) ? that.formData.Hour : 0;
						break;
					case 'minute':
						that.formData.Minute = !that.$utils.isEmpty(that.formData.Minute) ? that.formData.Minute : 0;
						break;
					default:
						break;
				}
			},
			OpenChoiceDate() { // 点击报工时长箭头，打开选择时间弹层
				this.showTimePickerBG = true;
				// 拼接时间，打开弹层显示对应时间
				this.DatetimeDataBG = String(this.formData.Hour) + ':' + String(this.formData.Minute);
			},
			formatter(type, data) { // 时间选择器数据格式化
				let value = +data;
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				if (type === 'hour') {
					if (value < 10) {
						value = '0' + value
					}
					return `${value}小时`
				}
				if (type === 'minute') {
					if (value < 10) {
						value = '0' + value
					}
					return `${value}分钟`
				}
				return value
			},
			ClosePickerBG() {
				this.showTimePickerBG = false;
			},
			ConfirmTimeBG(data) { // 报工时长时间选择器确认按钮
				let that = this;
				let TheData = data.value.split(':');
				let formattedArray = TheData.map(item => parseInt(item));

				this.formData.Hour = String(formattedArray[0]);
				this.formData.Minute = String(formattedArray[1]);
				that.ChangeDate();

				that.ClosePickerBG();

			},
			openBaseScreen(str, type) { // 前往筛选页
				let that = this;

				if (type == 'radio') {
					let obj = null;
					let url = '/commonPage/Tool/baseScreen';

					if (str == '生产车间') {
						obj = {
							allowClear: false,
							cmd: 'XGD_Workshop',
							type: str,
							ListeningName: 'TicketsInfo_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: true, //是否分页
								SearchKey: 'SearchKey', //搜索关键词，应包含在param中
								showText: 'FWorkshopName', //查询结果显示的字段
								pageIndexStr: 'pageIndex', //分页页码字段，应包含在param中
								// subText: [{
								// 	label: '描述',
								// 	labelKey: 'desc'
								// }],
								ChoiceDataKey: 'FWorkshopID',
								ChoiceDataData: this.formData.FWorkshopID,
							},
							param: {
								SearchKey: '',
								PageIndex: 1,
								PageSize: 30
							}
						}
					} else if (str == '模具编号') {

						obj = {
							allowClear: false,
							cmd: 'PGD_GetMolud',
							type: str,
							ListeningName: 'TicketsInfo_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: '', //搜索关键词，应包含在param中
								showText: 'MoludCode', //查询结果显示的字段
								// pageIndexStr: 'pageIndex', //分页页码字段，应包含在param中
								// subText: [{
								// 	label: '描述',
								// 	labelKey: 'desc'
								// }],
								ChoiceDataKey: 'MoludID',
								ChoiceDataData: this.formData.MoludID,
							},
							param: {
								MoludCode: '', // 筛选条件
								MoludTypeID: this.formData.MoludTypeID || 0, // 类型ID
								MoludID: this.formData.MoludID || 0, // 模具ID
								ProductID: this.PageInfoData.ProductID, // 产品ID
							}
						}
					} else if (str == '设备') {

						obj = {
							allowClear: false,
							cmd: 'PGD_GetEquipment',
							type: str,
							ListeningName: 'TicketsInfo_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: '', //搜索关键词，应包含在param中
								showText: 'EquipmentCode', //查询结果显示的字段
								// pageIndexStr: 'pageIndex', //分页页码字段，应包含在param中
								// subText: [{
								// 	label: '描述',
								// 	labelKey: 'desc'
								// }],
								ChoiceDataKey: 'EquipmentID',
								ChoiceDataData: this.formData.EquipmentID,
							},
							param: {
								EquipmentTypeID: this.formData.EquipmentTypeID || 0, // 类型ID
								EquipmentCode: '', // 筛选条件
								EquipmentID: this.formData.EquipmentID || 0, // 设备ID
							}
						}
					} else if (str == '班次') {
						obj = {
							allowClear: false,
							cmd: 'Droplist_Shift',
							type: str,
							ListeningName: 'TicketsInfo_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: '', //搜索关键词，应包含在param中
								showText: 'ShiftName', //查询结果显示的字段
								// pageIndexStr: 'pageIndex', //分页页码字段，应包含在param中
								// subText: [{
								// 	label: '描述',
								// 	labelKey: 'desc'
								// }],
								ChoiceDataKey: 'ShiftID',
								ChoiceDataData: this.formData.ShiftID,
							},
							param: {}
						}
					} else if (str == '作业员') {
						obj = {
							allowClear: false,
							cmd: 'XGD_Employee',
							type: str,
							ListeningName: 'TicketsInfo_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: '', //搜索关键词，应包含在param中
								showText: 'EmplName', //查询结果显示的字段
								pageIndexStr: 'PageIndex', //分页页码字段，应包含在param中
								// subText: [{
								// 	label: '描述',
								// 	labelKey: 'desc'
								// }],
								ChoiceDataKey: 'EmplID',
								ChoiceDataData: this.formData.EmplName,
							},
							param: {
								EmplCode: '',
								Pageindex: 1,
								PageSize: 30
							}
						}
					} else if (str == '计时计件') {
						obj = {
							allowClear: false,
							cmd: '',
							type: str,
							ListeningName: 'TicketsInfo_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: true, //是否分页
								searchKey: '', //搜索关键词，应包含在param中
								showText: 'PieceTimeName', //查询结果显示的字段
								// pageIndexStr: 'pageIndex', //分页页码字段，应包含在param中
								// subText: [{
								// 	label: '描述',
								// 	labelKey: 'desc'
								// }],
								ChoiceDataKey: 'PieceTime',
								ChoiceDataData: this.formData.PieceTime,
							},
							param: {
								data: JSON.parse(JSON.stringify(this.PieceTimeNameData))
							}
						};

						url = '/commonPage/Tool/baseScreen?select=1';
					} else if (str == '派工单') {
						obj = {
							allowClear: false,
							cmd: 'XGD_WoSelectJob',
							type: str,
							ListeningName: 'TicketsInfo_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: '', //搜索关键词，应包含在param中
								showText: 'BillNO', //查询结果显示的字段
								// pageIndexStr: 'pageIndex', //分页页码字段，应包含在param中
								// subText: [{
								// 	label: '描述',
								// 	labelKey: 'desc'
								// }],
								ChoiceDataKey: 'JobOrderID',
								ChoiceDataData: this.formData.JobOrderID,
							},
							param: {
								WoOrderID: this.formData.WoOrderID,
								ProcedureID: this.formData.ProcedureID,
								WoPROCID: this.formData.WoPROCID
							}
						}
						console.log(JSON.stringify(obj))
					}

					this.$store.commit('ChangeAndSetStateData', {
						Name1: 'BaseScreenParm',
						data: obj
					})

					uni.navigateTo({
						url: url
					})

				}

			},
			closeInitTicketPopup() { // 关闭发起报工弹层
				let that = this;
				this.InitTicketPopup = false;

				// 清空数据
				Object.keys(that.formData).forEach((key) => {
					if (!['EmplID', 'EmplName', 'PieceTime', 'PieceTimeName',
							'ShiftID', 'ShiftName'
						].includes(key)) {
						if (that.formData[key] === null) {
							that.formData[key] = null;
						} else if (Array.isArray(that.formData[key])) {
							that.formData[key] = [];
						} else if (typeof that.formData[key] === 'object') {
							that.formData[key] = {};
						} else {
							that.formData[key] = '';
						}
					}
				});
			},
			Popup_Submit_Btn() { // 发起报工弹层提交按钮
				let that = this;

				this.$refs.uForm.validate().then(() => {

					let ManHour = +this.formData.Hour + +(+this.formData.Minute / 60);
					let obj = {
						WoOrderID: this.formData.WoOrderID, // 工单ID
						EquipmentID: this.formData.EquipmentID || 0, // 设备ID
						ProcedureID: this.formData.ProcedureID, // 工序ID
						FProcessMan: this.formData.EmplID, // 作业员ID
						MoludID: this.formData.MoludID || 0, // 模具ID
						SCDate: this.dateFormat(new Date(), 'Y-MM-dd hh:mm:ss'), // 生产日期
						ManHour: ManHour, // 工时
						PieceTime: this.formData.PieceTime, // 计时计件
						FDailyQtt: +this.formData.AwaitWorkQty || 0, // 合格数量
						IndustrialWaste: this.formData.IndustrialWaste || 0, // 工费数
						MaterialWaste: this.formData.MaterialWaste || 0, // 料废数
						FNgQty: +this.formData.FNgQty || 0, // 不良数量
						ShiftID: this.formData.ShiftID, // 班次
						FRemarks: this.formData.Remark, // 子表备注
						FCJType: that.FCJType, // 单据类别
					};


					let submitCmd = 'GD_InsertBG';
					if (that.FCJType == 1) {
						obj['JobOrderID'] = that.formData.JobOrderID;
						obj['JobPROCID'] = that.formData.JobPROCID;
						submitCmd = 'XGD_InsertBG';
					} else if (that.FCJType == 2) {
						obj['WoPROCID'] = this.formData.WoPROCID || 0; // 工单工序 
					}
					console.log(JSON.stringify(obj))
					// return

					that.Request.request(submitCmd, obj, function(ret) {
						console.log(JSON.stringify(ret))
						if (ret.data && ret.data.ds.length && ret.data.ds[0].status == 500) {
							uni.showToast({
								title: ret.data.ds[0].msg,
								icon: 'none',
								duration: 2000
							})
						} else {
							that.GetWorkInfo();
							uni.showToast({
								title: '提交成功'
							})
							that.closeInitTicketPopup();

							setTimeout(() => {
								that.getTicketsHistory();
								// 刷新报工列表
								uni.$emit('Refresh', {
									refresh: true
								});
								// 刷新工单列表
								uni.$emit('Refresh_List', {
									type: '刷新'
								})
							}, 300)
						}
					}, function(err) {
						console.log(JSON.stringify(err))
						if (err.data.status == 500) {
							uni.showToast({
								title: '请求中断，请重试',
								icon: 'none'
							})
						}
					});

				})
			},
			BackColor(data) { // 根据工艺路线状态，返回对应颜色
				// console.log(JSON.stringify(data))
				let ModelColor = null;
				let MenuBac = null;

				switch (data.FState) {
					case 0: // 未报工
						ModelColor = '#333';
						MenuBac = '#e7e7e7';
						break;
					case 1: // 已完成
						ModelColor = '#29c660';
						MenuBac = '#d9f7ed';
						break;
					case -1: // 指定完成
						ModelColor = '#d0d30b';
						MenuBac = '#fbffd7';
						break;
					case 2: // 已领料
						ModelColor = '#1696eb';
						MenuBac = '#adf0eb';
						break;
					case 3: // 部分报工
						ModelColor = '#1f93e1';
						MenuBac = '#daedfe';
						break;
					default:
						ModelColor = '#333';
						MenuBac = '#e7e7e7';
						break;
				}
				let obj = {
					ModelColor: ModelColor,
					MenuBac: MenuBac,
				}
				return obj;
			},
			BackMap(str, data) { // 根据传入的值返回对应的数据
				let that = this;
				switch (str) {
					case 'IsLinear':
						return data ? '是' : '否';
						break;
					default:
						break;
				}
			},
			GetWorkInfo() {
				let that = this;

				that.request1 = that.Request.PromiseRequest('XGD_SelectWoOrder', {
					WoOrderID: that.WoOrderID
				});

				let PageInfoData = [];
				let MaterialList = [];

				that.request1.promise.then((data) => {
					// console.log(data)

					if (data.status == 200) {
						PageInfoData = data.data.ds[0];

						MaterialList = data.data.ds2;
						return
					} else {

						setTimeout(() => {
							that.$refs.paging.endRefresh()
						}, 100)

						return uni.showToast({
							title: '请求中断，请重试'
						})
					}
				}).then((result) => {
					that.request1 = null;

					that.request2 = that.Request.PromiseRequest('XGD_WorkOrder_PROC', {
						WoOrderID: that.WoOrderID
					});
					return that.request2.promise;
				}).then((data) => {
					// console.log(data)

					that.request1 = null;
					that.request2 = null;
					if (data.status === 200) {

						function isImageUrl(url) {
							const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp',
								'.webp'
							]; // 更多图片格式可以添加  
							return imageExtensions.some(ext => url.endsWith(ext.toLowerCase()));
						}

						// 假设 data 是你从接口获取到的数据，imgUrl 是其中的一个属性  
						const Filepath = PageInfoData.Filepath;

						if (!that.$utils.isEmpty(Filepath)) {
							PageInfoData['PathType'] = '';
							if (isImageUrl(Filepath)) {
								PageInfoData.Filepath = that.Request.IPAgreement() + that.Request.serverIP() +
									Filepath;
								PageInfoData['PathType'] = 'Pic';
							} else {
								PageInfoData['PathType'] = 'File';
							}
							// console.log(PageInfoData.Filepath)

						}
						// console.log(PageInfoData)

						that.PageInfoData = PageInfoData;
						that.MaterialList = MaterialList;

						that.ProgressList = data.data.ds.map(item => {
							return {
								...item,
								ProgressNum: Number((+item.WCQty / +item.FPlanQty * 100).toFixed(2)) || 0,
								AwaitWorkQty: +item.FPlanQty - +item.FDailyQtt
							}
						});


						setTimeout(() => {
							that.$refs.paging.endRefresh()
						}, 100)

					} else {


						setTimeout(() => {
							that.$refs.paging.endRefresh()
						}, 100)

					}
					// 请求2成功的处理逻辑
				}).catch((error) => {
					// console.log(error)

					if (this.request1) {
						this.request1.requestTask.abort(); // 取消第一个请求
					}
					if (this.request2) {
						this.request2.requestTask.abort(); // 取消第二个请求
					}

					setTimeout(() => {
						that.$refs.paging.endRefresh()
					}, 100)

				});
			},

			preview(url) {
				// this.imgs = [url] //设置图片数组
				// #ifdef MP-WEIXIN
				this.$nextTick(() => {
					this.$refs.previewImage.open(url); // 传入当前选中的图片地址(小程序必须添加$nextTick，解决组件首次加载无图)
				})
				// #endif

				// #ifndef MP-WEIXIN
				this.$refs.previewImage.open(url); // 传入当前选中的图片地址
				// #endif
			},
			onLongpress(e) { //长按事件
				let that = this;
				uni.showActionSheet({
					itemList: ['保存到手机'],
					success: function(res) {
						// console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						that.savePhoto();
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			//保存图片到相册
			savePhoto() {
				let that = this;
				uni.showLoading({
					title: "保存中...",
					icon: "loading",
				});
				uni.getImageInfo({
					src: that.PageInfoData.Filepath, //更换这个url就可以
					success: function(image) {
						uni.saveImageToPhotosAlbum({
							filePath: image.path,
							success: function(res) {
								that.showPopup = false;
								uni.hideLoading();
								uni.showToast({
									title: '已存入相册'
								})

							},
							fail(error) {
								uni.hideLoading();
								uni.showToast({
									title: "保存失败，请稍后重试",
									icon: "none",
								});
							},
						});
					},
					fail(error) {
						console.log(error);
					},
				});
			},
			OpenFileBtn() { // 点击打开主表附件（非图片类型）
				let that = this;

				console.log(that.PageInfoData.Filepath)

				this.$utils.showLoading()

				let data = {
					ShowTitle: '查看附件',
					sopFile: that.PageInfoData.Filepath
				}
				// that.LocalText = 'FormNeedRemove';
				that.OpenFileLocal = {
					data: data,
					LocalText: 'FormNeedRemove'
				}

				that.throttledHandleScroll(data);
			},
			// async GetWorkInfos() { // 获取工单详情数据
			// 	let that = this;
			// 	try {
			// 		const mainInfoPromise = this.getMainInfo();
			// 		const sonDataPromise = this.getSonData();

			// 		// 同时调用三个方法并等待它们都完成
			// 		await Promise.all([mainInfoPromise, sonDataPromise]);

			// 		// that.PageInfoData = that.$store.state.GetWorkOrderInfo;
			// 		// 这里表示三个方法都成功调用并完成
			// 		// 在这里展示页面或执行其他逻辑
			// 	} catch (error) {
			// 		console.error('获取数据失败:', error);
			// 	}
			// },
			// getMainInfo() { // 获取主表信息
			// 	let that = this;
			// 	return new Promise((resolve, reject) => {
			// 		that.Request.request('XGD_SelectWoOrder', {
			// 			WoOrderID: that.WoOrderID
			// 		}, function(ret) {
			// 			if (ret.status == 200) {
			// 				// console.log(ret.data.ds2)
			// 				that.PageInfoData = ret.data.ds[0];

			// 				that.MaterialList = ret.data.ds2;
			// 				resolve();
			// 			} else {
			// 				reject('获取数据失败');
			// 			}
			// 		});
			// 	});
			// },
			// getSonData() { // 获取进度列表
			// 	let that = this;
			// 	return new Promise((resolve, reject) => {
			// 		that.Request.request('XGD_WorkOrder_PROC', {
			// 			WoOrderID: that.WoOrderID
			// 		}, function(ret) {
			// 			// console.log(JSON.stringify(ret))
			// 			if (ret.status == 200) {
			// 				that.ProgressList = ret.data.ds.map(item => {
			// 					return {
			// 						...item,
			// 						AwaitWorkQty: +item.FPlanQty - +item.FDailyQtt
			// 					}
			// 				});
			// 				resolve();
			// 			} else {
			// 				reject('获取生产进度失败');
			// 			}
			// 		});
			// 	});
			// },
			FileZeroBack(data) {
				let parts = data.split(' '); // 使用空格分割日期和时间部分
				let datePart = parts[0]; // 获取日期部分
				let timePart = parts[1]; // 获取时间部分
				let timeParts = timePart.split(':'); // 使用冒号分割时和分
				let hour = timeParts[0].padStart(2, '0'); // 补零处理小时部分
				let minute = timeParts[1].padStart(2, '0'); // 补零处理分钟部分
				return hour + ':' + minute;
			},
			getTicketsHistory() { // 获取生产履历
				let that = this;
				try {
					that.Request.request('XGD_Traceability', {
						WoOrderID: that.WoOrderID
					}, function(ret) {
						if (ret.status == 200) {
							let data = JSON.parse(JSON.stringify(ret.data.ds));
							let NewData = [];

							data.forEach(item => {

								item['Time'] = that.FileZeroBack(item.BillDate);

								let existingData = NewData.find(obj => obj.date === item.BillDate.split(
									' ')[0]);
								if (existingData) {
									existingData.ArrData.push(item);
								} else {
									NewData.push({
										date: item.BillDate.split(' ')[0],
										ArrData: [item]
									});
								}
							});

							that.HistoryList = JSON.parse(JSON.stringify(NewData));


							// resolve();
						} else {
							// reject('获取生产进度失败');
						}
					});
				} catch (e) {
					//TODO handle the exception
				}
			},
			ClickArrow(str) { // 点击展开箭头
				if (str == 'open') {
					this.ArrowType = true;
				} else {
					this.ArrowType = false;
				}
			},
			clickHandler(data) { // 切换Tab页签
				this.current = data.index;
			},
			deepClone(obj, hash = new WeakMap()) {
				// 判断是否为基本数据类型  
				if (typeof obj !== 'object' || obj === null) {
					return obj;
				}

				// 判断是否为日期对象  
				if (obj instanceof Date) {
					return new Date(obj);
				}

				// 判断是否为RegExp对象  
				if (obj instanceof RegExp) {
					return new RegExp(obj);
				}

				// 如果hash中有obj，则直接返回  
				if (hash.has(obj)) {
					return hash.get(obj);
				}

				// 初始化新的对象  
				let newObj = Array.isArray(obj) ? [] : {};

				// 将新对象存入hash  
				hash.set(obj, newObj);

				// 遍历对象的属性  
				for (let key in obj) {
					if (obj.hasOwnProperty(key)) {
						newObj[key] = this.deepClone(obj[key], hash);
					}
				}

				return newObj;
			},
			// 使用节流封装的事件处理函数  
			throttledHandleScroll: throttle(function() {
				let that = this;
				if (uni.getStorageSync(that.OpenFileLocal.LocalText)) {
					that.$utils.hideLoading();
					open.openFile({
						filename: uni.getStorageSync(that.OpenFileLocal.LocalText),
						title: that.OpenFileLocal.data.ShowTitle,
						isShowBackIcon: true
					}, ret => {

						if (ret.code == -3) {
							// 文件路径无效,请检查文件是否存在
							// 上手清除一遍，然后重新调用查看附件
							uni.removeSavedFile({
								filePath: uni.getStorageSync(that.OpenFileLocal.LocalText),
								complete: function(res) {
									console.log(res);
									uni.removeStorageSync(that.OpenFileLocal.LocalText)
									that.openDocument();
								}
							});
						} else {
							console.log(JSON.stringify(ret))
							that.$utils.hideLoading();
						}

					});
				} else {
					that.openDocument();
				}
			}, 250), // 设置节流时间为 250 毫秒 
			OpenWorkBook(data) { // 打开作业指导书
				let that = this;
				that.$utils.showLoading();

				data['ShowTitle'] = data['ProcedureName'];

				// that.LocalText = 'NeedRemove';
				that.OpenFileLocal = {
					data: data,
					LocalText: 'NeedRemove'
				}

				that.throttledHandleScroll(data);

			},
			openDocument() { // 打开浏览
				var that = this;

				let data = that.OpenFileLocal.data;
				// console.log(data)

				let ServerIP = that.Request.serverIP();
				data.url = that.Request.IPAgreement() + ServerIP + data.sopFile;
				uni.downloadFile({
					url: data.url,
					success: function(res) {
						var filePath = plus.io.convertLocalFileSystemURL(res.tempFilePath);
						// console.log(JSON.stringify(filePath))
						that.$utils.hideLoading();
						// 记录一下地址，等界面打开的时候就删除掉
						uni.setStorageSync(that.OpenFileLocal.LocalText, filePath)
						open.openFile({
							filename: filePath,
							title: data.ShowTitle,
							isShowBackIcon: true
						}, ret => {
							// console.log(JSON.stringify(ret))
							that.$utils.hideLoading();
						});
					}
				})
			},
			SubWorkBtn(data, index) { // 点击报工
				let that = this;
				that.InitTicketPopup = true;
				try {
					// console.log(JSON.stringify(data))

					that.PopupTopNums = Object.assign(that.PopupTopNums, data);
					that.PopupIndex = index + 1;

					let newData = {};
					newData = that.deepClone(data);

					if (newData.hasOwnProperty('FNgQty')) {
						newData['FNgQty'] = '';
					}

					that.formData = Object.assign(that.formData, newData);

					// that.Request.request('GD_InsertBG', {
					// 	ProcedureID: data.ProcedureID,
					// 	FDailyQtt: data.AwaitWorkQty,
					// 	WoOrderID: data.WoOrderID,
					// 	WoPROCID: data.WoPROCID,
					// }, function(ret) {
					// 	console.log(JSON.stringify(ret))
					// });
				} catch (e) {
					//TODO handle the exception
					uni.showToast({
						title: '报工异常，请重试'
					})
				}
			},
			EditOrderBtn() { // 修改工单
				uni.navigateTo({
					url: './CreateTicket?WoOrderID=' + this.WoOrderID + '&openListen=' + 'ChangeTicketInfo'
				})
			},
		}
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		height: 100vh;
		background-color: #f9f9f9;


		uni-button {
			margin-left: initial !important;
			margin-right: initial !important;
		}

		.TypeText {
			width: fit-content;
			padding: 4px 10px;
			font-size: 14px;
			letter-spacing: 1px;
			color: #333;
			font-weight: 600;
			background-color: #e7e7e7;
			border-radius: 99999px;
		}

		.TopCardBox {
			position: relative;
			background-color: #fff;
			padding: 20px 15px 0;

			.ApprovalIcon {
				position: absolute;
				right: 20rpx;
				bottom: 20rpx;
			}


			.BillNO {
				margin-top: 10px;
			}
		}

		.FilterBox {
			padding: 15px 20px;

			.Filter_right {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				color: #505050;
				font-size: 16px;
			}
		}

		.MainBox {
			flex: 1;
			overflow: auto;
			position: relative;


			.Main_CardListBox {
				padding: 10px 15px;

				>.CardBox {
					position: relative;
					margin-bottom: 20rpx;
					background-color: #fff;
					padding: 15px;
					overflow: hidden;
					border-radius: 12px;
					// min-height: 300px;
					box-shadow: 0 0 8px -7px #333;

					.Xuhao_YL {
						position: absolute;
						left: 0;
						top: 0;
						min-width: 24px;
						height: 24px;
						line-height: 24px;
						background-color: #51d0d0;
						border-radius: 0 0 10px 0;
						text-align: center;
						color: #fff;
					}

					.Main_Card_Top {
						display: flex;
						align-items: center;
						justify-content: space-between;

						.OrdinalBox {
							width: fit-content;
							min-width: 24px;
							height: 24px;
							border-radius: 9999px;
							background-color: #51d0d0;
							color: #fff;
							font-size: 14px;
							line-height: 24px;
							text-align: center;
						}

						.Title_Text {
							margin-left: 6px;
							font-weight: 600;
							font-size: 14px;
						}
					}

					.CommonBox {
						border-radius: 8px;
						background-color: #f7f7f7;
						padding: 10px 10px;
						margin-top: 15px;
						display: flex;
						align-items: center;
						justify-content: space-evenly;

						.TextBox {
							display: flex;
							flex-direction: column;
							align-items: center;
							flex: 1;
						}

						.BottomText {
							margin-top: 14px;
						}

						.LeftIcon {
							width: 30px;
							height: 30px;
							line-height: 30px;
							font-size: 18px;
							border-radius: 8px;
							color: #fff;
							background-color: #01b87d;
							text-align: center;
						}

						.CenterBox {
							flex: 1;
							border-radius: 8rpx;
							padding: 2rpx 10rpx;
						}
					}

					.ShowSigningWork {
						display: flex;
						justify-content: flex-end;
						align-items: center;
						margin-top: 10px;

						.button {
							padding: 0rpx 10rpx;
							border-radius: 99999px;
							min-width: 120px;
							background-color: #fff;
							zoom: .8;
							margin-left: 6px !important;
						}
					}
				}
			}
		}

		.BottomBox {
			width: 100%;
			// height: 70px;
			// line-height: 70px;
			padding: 6px 15px;
			border-top: 1px solid #efefef;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			background-color: #fff;
			// padding-bottom: env(safe-area-inset-bottom) / 2;

			// padding-bottom: constant(safe-area-inset-bottom);
			// padding-bottom: env(safe-area-inset-bottom);
		}

	}

	.Popup_Main {

		.Popup_Main_Content {
			height: 90vh;

			.navbar_LeftBox {
				color: #fff;
				font-size: 18px;

				.Xuhao {
					width: fit-content;
					min-width: 24px;
					height: 24px;
					border: 2px solid #fff;
					border-radius: 24px;
					line-height: 24px;
					text-align: center;
					font-weight: 600;
					margin-right: 8px;
					font-size: 16px !important;
				}
			}

			.Popup_Main_Content_MainBox {
				.u-grid {
					padding: 20rpx 10rpx;
					background-color: #fff;

					.u-grid-item {
						font-size: 28rpx;

						.PopupGirdBox {
							color: #999;
						}

						&:last-child .grid-text {
							color: #e13a2b;
						}

						.grid-text {
							margin-top: 20rpx;

						}
					}
				}
			}
		}

		.Popup_Form {

			.Form_Item_top {
				margin-top: 10px;
			}

			.u-form-item {
				background-color: #fff !important;
				padding: 0 6px 0 12px;

				.u-form-item__body {
					padding: 8px 0 !important;

					.uni-input-placeholder {
						font-size: 12px;
					}
				}


				// 起止时间
				.ChoiceTimesBox {
					width: 100%;
					display: flex;
					align-items: center;

					.TimeBox {
						flex: 1;
						display: flex;
						align-items: center;
						justify-content: space-evenly;

						.timer {
							width: 100%;
							flex: 2;
							display: flex;
							flex-direction: column;
							font-size: 28rpx;
							color: #333;

							text:first-child {
								margin-bottom: 10px;
							}

							text:last-child {
								height: 20px;
								font-size: 14px;
							}
						}

						.Icon {
							flex: 1;
						}
					}
				}



			}

		}
	}
</style>